/**
 * 分发工作
 *
 * @author fireway
 * @since 2019年 03月 28日 星期四 07:18:12 CST
 */
package concurrency;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class CarBuilder {
    public static void main(String[] args) {
        CarQueue chassisQueue = new CarQueue();
        CarQueue finishingQueue = new CarQueue();

        ExecutorService exec = Executors.newCachedThreadPool();

        RobotPool robotPool = new RobotPool();
        exec.execute(new EngineRobot(robotPool));
        exec.execute(new DriveTrainRobot(robotPool));
        exec.execute(new WheelRobot(robotPool));

        exec.execute(new Assembler(chassisQueue, finishingQueue, robotPool));
        exec.execute(new Reporter(finishingQueue));

        // Start everything running by producing chassis
        exec.execute(new ChassisBuilder(chassisQueue));

        try {
            TimeUnit.SECONDS.sleep(7);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        exec.shutdownNow();
    }
}
